import request from '@/util/require'
import {computed} from "vue"
import { usePortStore } from '@/stores/index'
const { getPort, getUserInfo } = usePortStore()

//wifi列表地址
const baseURL = "http://192.168.150.1:8000"
//登录基地址
const loginURL = "http://47.94.1.69:6500"
//登录后的地址
const afterURL = 'http://47.94.1.69:'

const pocketURL = computed(() => {
  return "http://47.94.1.69:" + (usePortStore().getPort() + 1)
  // const afterURL = usePortStore().baseURL
  // return "http://" + afterURL + ":8000"
})


const casaOSURL = computed(() => {
  return "http://47.94.1.69:" + (usePortStore().getPort() + 1)
  // const afterURL = usePortStore().baseURL
  // return "http://" + afterURL + ":81"
})


/** ************wifi列表************/
export const wifiList = () => request({
  baseURL: "http://192.168.150.1:8000",
  method: 'get',
  url: '/wifi-list',
})
/** ************wifi列表************/
export const connectWifi = (data) => request({
  baseURL: "http://192.168.150.1:8000",
  method: 'post',
  url: '/connect-wifi',
  data
})
export const getPeopelByTimeSort = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/getpeopelByTimeSort'
})

/** ************wifi列表************/
export const wifiInfo = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'get',
  url: '/wifi-info',
})



export const login = (data) => request({
  baseURL: loginURL,
  method: 'get',
  url: '/activate/?device_id=' + data.deviceId
})
export const nasLogin = (data) => {
  return request({
    baseURL: casaOSURL.value,
    method: 'post',
    data,
    url: '/v1/users/login'
  })
}

export const getSearch = (data) => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/search',
  headers: {
    'Content-Type': 'application/json'
  },
})
export const downloadFile = (filePath) => {
  window.open(casaOSURL.value + '/v3/file' + '?token=' + usePortStore().getUserInfo().token.access_token + '&' + 'path=' + filePath)
}



export const downloadFiles = (files) => {
  window.open(casaOSURL.value + '/v1/batch' + '?token=' + usePortStore().getUserInfo().token.access_token + '&' + 'files=' + files)
}

export const uploadImg = (data) => {
  const token = usePortStore().getUserInfo().token.access_token
  return request({
    baseURL: casaOSURL.value,
    method: 'post',
    data,
    url: '/v2/casaos/file/upload',
    headers: {
      authorization: token
    }
  })
}

//知识库问答
export const query = (data) => request({
  // baseURL: baseURL,
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/query',
  data,
  headers: {
    'Content-Type': 'application/json'
  },
  onDownloadProgress: (res) => {
    // console.log(res)
  }
})

export const createPPT = (data) => request({
  // baseURL: baseURL,
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/createReport'
})

export const GeneratePPT = (data, currentRate) => request({
  // baseURL: "http://localhost:3000",
  responseType: 'blob',
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/GeneratePPT'
  // url: '/download'
})


export const textPolish = (data) => request({
  // baseURL: baseURL,
  baseURL: pocketURL.value+ '/ai_pocket',
  method: 'post',
  data,
  url: '/textPolish'
})


export const getNoteList = () => request({
  headers:{
    'Authorization':usePortStore().getUserInfo().token.access_token,
    'Content-Type': 'application/json'
  },
  baseURL: casaOSURL.value,
  method: 'get',
  url: '/v1/folder?path=/DATA/notes',
})


export const removeNote = (data) => request({
  headers:{
    'Authorization':usePortStore().getUserInfo().token.access_token
  },
  data,
  baseURL: casaOSURL.value,
  method: 'DELETE',
  url: '/v1/batch',
})
export const getAllCityInfo = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/getAllCityInfo'
})
export const getAllTags = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/getAllTags'
})
export const getCityByTimeSort = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/getCityByTimeSort'
})

export const downLoadNote = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  data,
  baseURL: pocketURL.value,
  method: 'post',
  url: '/ai_pocket/downloadFiles',
  responseType: 'blob',
})


export const htmlToDocx = (data) => request({
  data,
  baseURL: pocketURL.value,
  method: 'post',
  url: '/ai_pocket/html2word',
  responseType: 'blob',
})

export const getTagImagesByTimeSort = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL:  pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/getTagImagesByTimeSort'
})

export const getAllImagesByTimeSort = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/getAllImagesByTimeSort'
})
export const reNameId = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/rename_id'
})
export const getAllPhotoTag = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/get_all_photo_tag'
})

export const getAllPeople = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/getAllPeople'
})

export const addIdAttribute = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/add_id_attribute'
})

export const removeIdAttribute = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/remove_id_attribute'
})

export const listNote = (data) => request({
  baseURL:pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/listNote'
})
export const filtration = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL:pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/filtration'
})

export const searchPhoto = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL:pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/search_photo'
})

export const testNetwork = (ip) => request({
  baseURL: 'http://' + ip + ':8000' + '/ai_pocket',
  method: 'get',
  url: '/wifi-list',
})



export function getImgUrl (filePath) {
  return casaOSURL.value + '/v3/file' + '?token=' + usePortStore().getUserInfo().token.access_token + '&' + 'path=' + filePath
}

